<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>优惠券</title>
  <link rel="stylesheet" href="../css/mycoupon.css">
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../js/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="header">
  <div class="nav">
    <div class="logo">
      <a href="../index.html"><img src="../images/mycoupon-logo.png" alt="" class="logoimg"></a>
    </div>
    <div class="title">
      我的秒杀
    </div>

    <div class="nav_r">
      <div class="search">
        <div class="search_form">
          <input type="text" class="sc-text">
          <button>搜索</button>
        </div>
      </div>
      <div class="dropdown">
        <i><img src="../images/mycoupon-shopcar.svg" alt=""></i>
        <a href="../personal/myShopcar.html">
          我的购物车
        </a>
      </div>
    </div>
  </div>
</div>
<div class="contain">
  <div class="content">
    <div class="sub">
      <div class="menu">
        <dl class="menupart1">
          <dt class="ordercenter">订单中心</dt>
          <dd><a class="wodedingdan" href="">我的订单</a></dd>
          <dd><a href="${pageContext.request.contextPath}/personal/myEvaluation.html">我的评价</a></dd>
        </dl>
        <dl class="mywallet">
          <dt class="ordercenter">我的钱包</dt>
          <dd><a href="${pageContext.request.contextPath}/personal/myCoupon.jsp">优惠券</a></dd>
          <dd><a href="${pageContext.request.contextPath}/personal/person.jsp">积分</a></dd>
        </dl>
        <dl class="myguanzhu">
          <dt class="ordercenter">我的关注</dt>
          <dd><a href="">关注商品</a></dd>
          <dd><a href="">关注店铺</a></dd>
        </dl>
      </div>
    </div>
    <!-- =================右侧优惠券 =================-->
    <div class="main">
      <!-- 头部导航 -->
      <div class="mod-coupon">
        <div class="mt">
          <h3>优惠券</h3>
          <div class="extra-r">
            <a class="viplink" href="../coupon/allCoupon.jsp">
              <img src="../images/mycoupon-mt-icon.png" class="coupon-icon">
              ${result}
            </a>
          </div>
        </div>
      </div>
      <!-- 商城优惠券页面 -->
      <div class="mod-main">
      <div class="coupon-top">
        <ul class="extra-l">
          <li>
            <a href="#">商城</a>
          </li>

        </ul>
        <div class="extra-r">
          <a href="#">优惠券规则说明</a>
        </div>
      </div>
      <div class="coupon-content">
        <div class="coupon-toolbar">
          <div class="c-sort">
            <ul>
              <li class="fore1">
                <div class="coupon-type">
                  <div class="dt">
                    可用优惠券
                    <b></b>
                  </div>
                  <div class="dd">
                    <ul class="dd-menu">
                      <li><a href="#"><b></b>可用优惠券</a></li>
                      <li><a href="#"><b></b>已用优惠券</a></li>
                      <li><a href="#"><b></b>过期优惠券</a></li>
                    </ul>
                  </div>
                </div>
              </li>
              <li class="fore2">
                <!-- <div class="coupon-type">
                    <div class="dt">
                        全部劵类型
                        <b></b>
                    </div>
                    <div class="dd">
                        <ul class="dd-menu">
                            <li><a href="#"><b></b>可用优惠券</a></li>
                            <li><a href="#"><b></b>已用优惠券</a></li>
                            <li><a href="#"><b></b>过期优惠券</a></li>
                        </ul>
                    </div>
                </div> -->
              </li>
              <li class="curr">
                <a href="#">新到账</a>
              </li>
              <li class="expiring">
                <a href="#">即将过期</a>
              </li>
            </ul>
          </div>
        </div>
        <div class="coupon-items">

          <%--<div class="coupon-item">
            <div class="c-type">
              <div class="c-price">
                <em>￥</em>
                <strong>5</strong>
                <span class="type">电劵</span>
              </div>
              <div class="c-limit">满6可用</div>
              <div class="c-time">2022.08.25-2022.08.28</div>
              <div class="c-type-top"></div>
              <div class="c-type-bottom"></div>
            </div>
            <div class="c-msg">
              <div class="c-range">
                <div class="range-item">
                  <span class="label">限品类：</span>
                  <span class="txt">仅可购买闪电秒杀自营商品</span>
                  <b class="rge-img" style="display: inline-block;"></b>
                  <div class="item-tips" >
                    <s></s>
                    <div class="tips">仅可购买闪电秒杀自营商品</div>
                  </div>
                </div>
                <div class="range-item">
                  <span class="label">限平台：</span>
                  <span class="txt">全平台</span>
                </div>
                <div class="range-item">
                  <span class="label">劵编号：</span>
                  <span class="txt">343030248881</span>
                </div>
                <div class="range-item"></div>
                <div class="range-item"></div>
              </div>
              <div class="op-btns">
                <a href="#"><span class="txt">立即使用</span></a>
                <b></b>
              </div>
            </div>
            <div class="c-del"></div>
          </div>--%>
        </div>
        <div class="ui-page-wrap">
          <div id="demo2-1"></div>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
<div class="service"></div>
<script>
  var token=localStorage.getItem("token")
  $.ajax({
    type:"GET",
    url:"${pageContext.request.contextPath}/mycoupon",
    headers: {'token': token},
    success:function (data){
      for(var i=0;i<data.length;i++){
        if (data[i] !== null) {
          console.log(data[i])
          var mycouponNumber = data[i].mycouponNumber;//劵编号
          var mycouponGetTime =data[i].mycouponGetTime;//获取时间
          var mycouponPrice =data[i].mycouponPrice;
          var xx = data[i].xx.substring(0,10)//结束时间
          var yy = data[i].yy//满减
          console.log("返回得到的数据："+JSON.stringify(data))
          console.log("mycouponNumber"+mycouponNumber)
          console.log("starttime"+mycouponGetTime)
          console.log("endtime"+xx)
          console.log("满减"+yy)
          var couponlist ='<div class="coupon-item">\n' +
                  '            <div class="c-type">\n' +
                  '              <div class="c-price">\n' +
                  '                <em>￥</em>\n' +
                  '                <strong>'+mycouponPrice+'</strong>\n' +
                  '                <span class="type">电劵</span>\n' +
                  '              </div>\n' +
                  '              <div class="c-limit">'+yy+'</div>\n' +
                  '              <div class="c-time">'+mycouponGetTime+'</div>\n'+
                  '              <div class="c-span">-</div>\n'+
                  '              <div class="c-endtime">'+xx+'</div>\n' +
                  '              <div class="c-type-top"></div>\n' +
                  '              <div class="c-type-bottom"></div>\n' +
                  '            </div>\n' +
                  '            <div class="c-msg">\n' +
                  '              <div class="c-range">\n' +
                  '                <div class="range-item">\n' +
                  '                  <span class="label">限品类：</span>\n' +
                  '                  <span class="txt">仅可购买闪电秒杀自营商品</span>\n' +
                  '                  <b class="rge-img" style="display: inline-block;"></b>\n' +
                  '                  <div class="item-tips" >\n' +
                  '                    <s></s>\n' +
                  '                    <div class="tips">仅可购买闪电秒杀自营商品</div>\n' +
                  '                  </div>\n' +
                  '                </div>\n' +
                  '                <div class="range-item">\n' +
                  '                  <span class="label">限平台：</span>\n' +
                  '                  <span class="txt">全平台</span>\n' +
                  '                </div>\n' +
                  '                <div class="range-item">\n' +
                  '                  <span class="label">劵编号：</span>\n' +
                  '                  <span class="txt">'+mycouponNumber+'</span>\n' +
                  '                </div>\n' +
                  '                <div class="range-item"></div>\n' +
                  '                <div class="range-item"></div>\n' +
                  '              </div>\n' +
                  '              <div class="op-btns">\n' +
                  '                <a href="#"><span class="txt">立即使用</span></a>\n' +
                  '                <b></b>\n' +
                  '              </div>\n' +
                  '            </div>\n' +
                  '            <div class="c-del"><span class="dell" style="display: none">'+mycouponNumber+'</span></div>\n' +
                  '          </div>'
          // $(".dell").hide()
          $(".coupon-items").append(couponlist);
        }

      }

    }
  })
  document.querySelector(".coupon-items").onclick = function (event) {
    var ele = event.target;
    if(ele.nodeName == "DIV" && ele.className == "c-del") {
      var number=event.target.children[0].innerHTML
      $.ajax({
        type:"POST",
        url:"${pageContext.request.contextPath}/deleteCoupon/"+number,
        success:function (data){
          alert("删除成功")
          window.location.href="${pageContext.request.contextPath}/personal/myCoupon.jsp"
        }
      })
      console.log("event"+event.target.children[0].innerHTML)
      console.log("event"+event.target.nodeName)
      console.log("event"+event.target.className)
    }

  }
</script>
<script src="../layui/layui.js"></script>
<script>
  layui.use(['laypage', 'layer'],function(){
    var laypage = layui.laypage
            ,layer = layui.layer;

    laypage.render({
      elem: 'demo2-1'
      ,count: 12
      ,theme: 'rgb(230,0,0)'
    });
  })

  var token = localStorage.getItem("token")
  $(".wodedingdan").attr("href","/demo/getAllOrders/" + token);

</script>
</body>
</html>


